const {database} = require("@common/config")

class RegisterService {
  async create(username,password){
    try {
      const statement = `INSERT INTO user (name,password) VALUES (?,?)`
      const [result] = await database.promise().execute(statement,[username,password])
      return result
    } catch (error) {
      throw new Error(error)
    }
  }

  async verifyName(username){
   try {
    const statement = `SELECT * FROM user WHERE name = ?`
    const [result] = await database.promise().execute(statement,[username])
    return result[0] ?? []
   } catch (err) {
      throw new Error(err)
   }
  }
}


module.exports = new RegisterService()